<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>精进智能</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
</head>

<body ontouchstart>
<header>
    <div><h1>
        订单确认
    </h1></div>
</header>
<div class="bd">
    <div class="weui-form-preview">
        <div class="weui-form-preview__hd">
            <label class="weui-form-preview__label">付款金额</label>
            <em class="weui-form-preview__value">¥2400.00</em>
            <input class="weui-input" hidden=true id="transAmt" name="transAmt" placeholder="请输出要支付的金额" type="number" value="1">
            <input class="weui-input" hidden=true id="openid" name="openid" th:value="${openid}">
        </div>
        <div class="weui-form-preview__bd">
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">商品</label>
                <span class="weui-form-preview__value">买个帕拉梅拉</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">标题标题</label>
                <span class="weui-form-preview__value">很贵很贵很贵</span>
            </div>
            <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">标题标题</label>
                <span class="weui-form-preview__value">很长很长的名字很长很长的名字很长很长的名字很长很长的名字很长很长的名字</span>
            </div>
        </div>
        <div class="weui-form-preview__ft">
            <button class="weui-form-preview__btn weui-form-preview__btn_primary" onclick="placeOrder()" id="btn">确定
            </button>
        </div>
    </div>


</div>

<script>

    function placeOrder() {
        var transAmt = $("#transAmt").val();
        var openid = $("#openid").val();
        var cusRemark = "测试下单";
        var userId = 499295;
        $.alert(transAmt);
        $.ajax({
            type: 'POST',
            data: {
                "transAmt": transAmt,
                "openId": openid,
                "cusRemark": cusRemark,
                "userId": userId
            },
            url: "/mobile/orderIndex/placeOrder",
            success: function (json) {
                if (json.code == 0) {
                    pay(json.data.appId, json.data.timeStamp, json.data.signType, json.data.nonceStr, json.data.package, json.data.sign)
                } else {
                    parent.layer.alert(data.msg)
                }
            }
        });
    }

    function pay(appId, timeStamp, signType, nonceStr, packages, paySign) {

        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady(appId, timeStamp, signType, nonceStr, packages, paySign);
        }

    }


    //h5唤起微信支付
    function onBridgeReady(appId, timeStamp, signType, nonceStr, packages, paySign) {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId": appId,
                "timeStamp": timeStamp,
                "nonceStr": nonceStr,
                "package": packages,
                "signType": signType,
                "paySign": paySign
            },
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    alert("支持成功");
                } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
                    alert("取消支付");
                }
            }
        );
    }


    //    function onBridgeReady(appId, timeStamp, nonceStr, package, signType, paySign){
    //        WeixinJSBridge.invoke(
    //            'getBrandWCPayRequest', {
    //                "appId" : appId,
    //                "timeStamp" : timeStamp,
    //                "nonceStr" : nonceStr,
    //                "package" : package,
    //                "signType" : signType,
    //                "paySign" : paySign
    //            },
    //            function(res){
    //                if(res.err_msg == "get_brand_wcpay_request:ok" ){
    //                    alert("支付成功!");
    //                } else {
    //                    alert("支付失败!");
    //                }
    //            });
    //    }

</script>
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
<!-- 如果使用了某些拓展插件还需要额外的JS -->
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/swiper.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/city-picker.min.js"></script>
</body>
</html>